package com.sunagy.demand.backend;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * desc：Swagger Restful 文档生成工具配置文件
 * author：三餘無夢生
 * date：2018/4/11
 * time：下午4:01
 */
@EnableSwagger2
@Configuration
public class Swagger2Config {

    private List<ApiKey> securitySchemes() {
        ArrayList<ApiKey> arrayList = new ArrayList();
        ApiKey apiKey = new ApiKey("Authorization","Authorization","header");
        arrayList.add(apiKey);
        return arrayList;
    }

    @Bean
    public Docket buildDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInf())
                .host("maz-demand.sunagy.cn")
                .securitySchemes(securitySchemes())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunagy.demand.backend.controller"))//controller路径
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo buildApiInf() {
        return new ApiInfoBuilder()
                .title("RestAPI Docs")
                .termsOfServiceUrl("https://maz-demand.sunagy.cn")
                .build();

    }
}